package com.groupbuying.redpacket.config;

import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.groupbuying.redpacket.constants.MQConstans;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

import static com.groupbuying.redpacket.service.impl.RuleServiceImpl.LOGGER;

/**
 * @ClassName RedPacketMQProducer
 * @Description: TODO   红包mq配置类
 * @Author srlg3
 * @Date 2019/11/27
 * @Version V1.0
 **/
@Configuration
public class RedPacketMQProducer {

    Logger logger = LoggerFactory.getLogger(RedPacketMQProducer.class);

    @Bean
    public Producer getRedPacketMQProducer() {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.AccessKey, MQConstans.ACCESS_KEY);
        properties.put(PropertyKeyConst.SecretKey, MQConstans.SECRET_KEY);
        properties.put(PropertyKeyConst.NAMESRV_ADDR, MQConstans.NAMESRV_ADDR);
        Producer producer = ONSFactory.createProducer(properties);
        try {
            producer.start();
            logger.info("producer is start !!!  groupId:{" + MQConstans.REDPACKET_ADDAMT_PRODUCERID + "}");
        } catch (Exception var4) {
            logger.error(String.format("producer is error  groupId:{" + MQConstans.REDPACKET_ADDAMT_PRODUCERID + "}", var4.getMessage(), var4));
        }

        return producer;
    }
}
